package emulator.shell.GUI.profiling;

import java.util.Collection;

import javax.swing.table.TableModel;
import javax.swing.tree.TreeModel;

import emulator.assembler.AddressDictionary;
import emulator.hardware.debug.profiling.CodeSegment;

public class ProfilingStatisticsVM
{
	private CodeTableModel codeTableModel = new CodeTableModel();
	private CallTableModel callTableModel = new CallTableModel();
	private CallTreeModel callTreeModel = new CallTreeModel(); 

	public TableModel getCodeTableModel()
	{
		return codeTableModel;
	}

	public TableModel getCallTableModel()
	{
		return callTableModel;
	}
	
	public TreeModel getCallTreeModel()
	{
		return callTreeModel;
	}
	
	public void addAddressStatistics(int address, int sumTicks, int hitCount, String label)
	{
		codeTableModel.addData(new CodeTableData(address, sumTicks, hitCount, label));
	}

	public void setTotalTicks(long totalTicks)
	{
		codeTableModel.setTotalTicks(totalTicks);
	}

	public int getAddressAtCodeLine(int rowIndex)
	{
		return codeTableModel.getAddressAtRow(rowIndex);
	}

	public int getAddressAtCall(int rowIndex)
	{
		return callTableModel.getAddressAtRow(rowIndex);
	}

	public void prepareCodeSegment(CodeSegment codeSegment, String label)
	{
		callTableModel.prepareCodeSegment(codeSegment, label);
	}

	public void processCodeSegment(CodeSegment codeSegment)
	{
		callTableModel.processCodeSegment(codeSegment);
	}

	public void addTopLevelSegments(Collection<CodeSegment> topLevelSegments, AddressDictionary labelMap)
	{
		for (CodeSegment codeSegment : topLevelSegments)
		{
			callTreeModel.getRootNode().addChild(codeSegment, labelMap);
		}
	}
	
	public void postProcess()
	{
		codeTableModel.postProcess();
		callTableModel.postProcess();
	}
}
